package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lc.afbx.R;
import com.lc.afbx.adapters.QuestionAdapter;
import com.lc.afbx.conn.GetApiSetQuestions;
import com.lc.afbx.util.PrefrenceConfig;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/20.
 */
public class ProblemsActivity extends BaseActivity implements View.OnClickListener {


    private ListView problems_lv;
    private List<GetApiSetQuestions.Data> lists = new ArrayList<>();
    private QuestionAdapter adapter;

    private GetApiSetQuestions getApiSetQuestions = new GetApiSetQuestions(new AsyCallBack<GetApiSetQuestions.Info>() {

        @Override
        public void onSuccess(String toast, int type, GetApiSetQuestions.Info info) throws Exception {

            lists.addAll(info.dataList);

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_geren_changjianwenti);


        problems_lv = (ListView) findViewById(R.id.problems_lv);

        problems_lv.setDivider(null);

        problems_lv.setAdapter(adapter = new QuestionAdapter(context, lists));

        problems_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(context, ProblemDetailActivity.class);

                intent.putExtra(PrefrenceConfig.INTENT_TAG, lists.get(position).content);
                startActivity(intent);
            }
        });


        getApiSetQuestions.execute(this);

    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

        }


    }

}
